// 获取String中name=xxx的值
String.prototype.getQueryString = function (name) {
    var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"), r;
    if (r = this.match(reg))
        return unescape(r[2]);
    return null;
}
// 替换字符串中{0}{1}...
String.prototype.format = function (args) {
    if (arguments.length == 0)
        return null;

    var str = this;
    for (var i = 0; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}
String.prototype.endWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.startWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.isEmpty = function () {
    return this.trim() === '';
}
String.prototype.toDate = function () {
    var temp = this.toString();
    temp = temp.replace(/-/g, "/");
    var date = new Date(Date.parse(temp));
    return date;
}
Date.prototype.toFomatorString = function (formator) {
    var returnText = formator.toUpperCase();
    if (returnText.indexOf("YYYY") > -1) {
        returnText = returnText.replace("YYYY", this.getFullYear());
    }
    if (returnText.indexOf("MM") > -1) {
        returnText = returnText.replace("MM", this.getMonth() + 1);
    }
    if (returnText.indexOf("DD") > -1) {
        returnText = returnText.replace("DD", this.getDate());
    }
    if (returnText.indexOf("HH") > -1) {
        returnText = returnText.replace("HH", this.getHours());
    }
    if (returnText.indexOf("MI") > -1) {
        returnText = returnText.replace("MI", this.getMinutes());
    }
    if (returnText.indexOf("SS") > -1) {
        returnText = returnText.replace("SS", this.getSeconds());
    }
    if (returnText.indexOf("SI") > -1) {
        returnText = returnText.replace("SI", this.getMilliseconds());
    }
    return returnText;
}
// 继承实现
var __extends = this.__extends ||
    function (d, b) {
        function __() {
            this.constructor = d;
        }

        __.prototype = b.prototype;
        d.prototype = new __();
    }

// 计算字符串的字节数
var sizeof = function (str, charset) {
    var total = 0, charCode, i, len;
    charset = charset ? charset.toLowerCase() : '';
    if (charset === 'utf-16' || charset === 'utf16') {
        for (i = 0, len = str.length; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode <= 0xffff) {
                total += 2;
            } else {
                total += 4;
            }
        }
    } else {
        for (i = 0, len = str.length; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode <= 0x007f) {
                total += 1;
            } else if (charCode <= 0x07ff) {
                total += 2;
            } else if (charCode <= 0xffff) {
                total += 3;
            } else {
                total += 4;
            }
        }
    }
    return total;
}